//
//  SettingCell.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/11/17.
//  Copyright © 2016年 郑东喜. All rights reserved.
//  设置页面cell

import UIKit

// MARK:- 设置代理
protocol SettingCellDelegate {
//    func showLogVC()
    func logoutSel()
}

class SettingCell: UITableViewCell {
    
    //监听代理
    var delegate : SettingCellDelegate?
    
    //cell的文字
    var nameLabel: UILabel = {
        let lab = UILabel()
        lab.frame = CGRect(x: 50, y: 0, width: 200, height: 45)
        
        //文字左对齐
        lab.textAlignment = NSTextAlignment.left
        lab.font = UIFont.systemFont(ofSize: 14)
        return lab
    }()
    
    //前置图片
    lazy var imgView: UIImageView = {
        let img = UIImageView()
        //自适应放大
        img.contentMode = UIViewContentMode.scaleAspectFit
        img.frame = CGRect(x: 10, y: 10, width: 25, height: 25)
        return img
    }()
    
    //分割线
    lazy var line : UIView = {
       let lin = UIView()
        lin.frame = CGRect(x: 0, y: 45, width: UIScreen.main.bounds.size.width, height: 0.5)
       lin.backgroundColor = UIColor.lightGray
        return lin
    }()
    
    //退出按钮
    lazy var btn : UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor.orange
        btn.setTitle("退出", for: .normal)
        //退出按钮
        btn.frame = CGRect(x: 15, y: 0, width: Int(UIScreen.main.bounds.width - 30), height: 40)
        //单机事件
        
        btn.addTarget(self, action: #selector(SettingCell.logout), for: .touchUpInside)
        btn.layer.cornerRadius = 10
        return btn
    }()
    
    //尖角
    lazy var disclosureImg : UIImageView = {
        let img = UIImageView()
        
        img.contentMode = UIViewContentMode.scaleAspectFit
        img.frame = CGRect(x: UIScreen.main.bounds.width - 30, y: 7.5, width: 15, height: 30)
        
        return img
    }()
    
    //重写构造方法
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        disclosureImg.image = UIImage.init(named: "closuerimg")
        imgView.image = UIImage.init(named: "pass")
      
        addSubview(nameLabel)
        addSubview(imgView)
        addSubview(line)
        addSubview(btn)
        addSubview(disclosureImg)
        
        //去除高亮效果
        self.selectionStyle = .none
    }


    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(false, animated: false)
    }
}

//单机监听事件
extension SettingCell {
    @objc fileprivate func logout() -> Void {
        self.delegate?.logoutSel()

      }
}








